Object.defineProperty(exports, "__esModule", { value: !0 });
var e = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
  t = /^(?:[A-Za-z\d+\/]{4})*?(?:[A-Za-z\d+\/]{2}(?:==)?|[A-Za-z\d+\/]{3}=?)?$/;
function r(e) {
  var t = e.replace(/-/g, "+").replace(/_/g, "/");
  switch (t.length % 4) {
    case 0:
      break;
    case 2:
      t += "==";
      break;
    case 3:
      t += "=";
      break;
    default:
      throw "Illegal base64url string!";
  }
  try {
    return (function (e) {
      return decodeURIComponent(
        exports.weAtob(e).replace(/(.)/g, function (e) {
          var t = e.charCodeAt(0).toString(16).toUpperCase();
          return t.length < 2 && (t = "0" + t), "%" + t;
        }),
      );
    })(t);
  } catch (e) {
    return exports.weAtob(t);
  }
}
(exports.weBtoa = function (t) {
  for (
    var r, o, n, a, c = "", i = 0, d = (t = String(t)).length % 3;
    i < t.length;

  ) {
    if (
      (o = t.charCodeAt(i++)) > 255 ||
      (n = t.charCodeAt(i++)) > 255 ||
      (a = t.charCodeAt(i++)) > 255
    )
      throw new TypeError(
        "Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range.",
      );
    c +=
      e.charAt(((r = (o << 16) | (n << 8) | a) >> 18) & 63) +
      e.charAt((r >> 12) & 63) +
      e.charAt((r >> 6) & 63) +
      e.charAt(63 & r);
  }
  return d ? c.slice(0, d - 3) + "===".substring(d) : c;
}),
  (exports.weAtob = function (r) {
    if (((r = String(r).replace(/[\t\n\f\r ]+/g, "")), !t.test(r)))
      throw new TypeError(
        "Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.",
      );
    r += "==".slice(2 - (3 & r.length));
    for (var o, n, a, c = "", i = 0; i < r.length; )
      (o =
        (e.indexOf(r.charAt(i++)) << 18) |
        (e.indexOf(r.charAt(i++)) << 12) |
        ((n = e.indexOf(r.charAt(i++))) << 6) |
        (a = e.indexOf(r.charAt(i++)))),
        (c +=
          64 === n
            ? String.fromCharCode((o >> 16) & 255)
            : 64 === a
              ? String.fromCharCode((o >> 16) & 255, (o >> 8) & 255)
              : String.fromCharCode((o >> 16) & 255, (o >> 8) & 255, 255 & o));
    return c;
  }),
  (exports.default = function (e, t) {
    if ("string" != typeof e) throw "Invalid token specified";
    var o = !0 === (t = t || {}).header ? 0 : 1;
    try {
      return JSON.parse(r(e.split(".")[o]));
    } catch (e) {
      throw "Invalid token specified: " + e.message;
    }
  });
